package com.zhengjiang.cxf.webservice.config;

import com.zhengjiang.cxf.webservice.service.UserService;
import com.zhengjiang.cxf.webservice.service.impl.UserServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

@Configuration
public class CxfConfig {

    @Bean
    UserService userService(){
        return new UserServiceImpl();
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    SpringBus springBus(){
        return new SpringBus();
    }

    @Bean
    ServletRegistrationBean cxfServlet(){
        return new ServletRegistrationBean(new CXFServlet(),"/soap/*");
    }

    @Bean
    Endpoint endpoint(){
        Endpoint endpoint = new EndpointImpl(springBus(),userService());
        endpoint.publish("/user");
        return endpoint;
    }

}
